package com.msmall.community.common.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.msmall.base.util.Constants;


public class RootListener implements ServletContextListener {
	
	private static final Log logger = LogFactory.getLog(RootListener.class);

	public void contextInitialized(ServletContextEvent sce) {
		String rootpath = sce.getServletContext().getRealPath("/");
	    if (rootpath != null) {
	      rootpath = rootpath.replaceAll("\\\\", "/");
	    } else {
	      rootpath = "/";
	    }
	    if (!rootpath.endsWith("/")) {
	      rootpath = rootpath + "/";
	    }
	    Constants.ROOTPATH = rootpath;
	    logger.debug("Rootpath:" + rootpath);
	}
	
	public void contextDestroyed(ServletContextEvent sce) {
		//do nothing
	}

}
